home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
127_01
/
rap3.c
< prev
next >
Wrap
Text File
|
1985-03-09
|
14KB
|
553 lines
/*********************************************************************\
** .---------------------------------------------------------------. **
** | | **
** | | **
** | Copyright (c) 1981, 1982, 1983 by Eric Martz. | **
** | | **
** | | **
** | Permission is hereby granted to use this source | **
** | code only for non-profit purposes. Publication of | **
** | all or any part of this source code, as well as | **
** | use for business purposes is forbidden without | **
** | written permission of the author and copyright | **
** | holder: | **
** | | **
** | Eric Martz | **
** | POWER TOOLS | **
** | 48 Hunter's Hill Circle | **
** | Amherst MA 01002 USA | **
** | | **
** | | **
** `---------------------------------------------------------------' **
\*********************************************************************/
#include "rap.h"
/*-------------------------------------------------------------------------*/
getwrd(next)
/* STARTING AT THE POINTER *next, FINDS THE NEXT WORD AND SETS THE POINTERS
Wordbegin AND Wordend, MOVING *next TO THE CHARACTER AFTER Wordend. Wordlen
IS CALCULATED TAKING INTO ACCOUNT IMBEDDED POST_SS COMMANDS OR BACKSPACES.
RETURNS Wordlen WHICH IS ZERO IF LAST WORD WAS GOTTEN ON PREVIOUS CALL. IF
AN OPENING POST_SS_DELIMITER IS FOUND IN THE WORD, THE WORD MUST NOT END
UNTIL A CLOSING DELIMITER IS FOUND, TO PREVENT BREAKING A LINE WITHIN AN
ORIGINAL STRING TO BE POST-SUBSTITUTED. */
char **next;
{
char *p1, *p2;
int even_delim;
if (**next EQ NULL) return(0);
even_delim = YES;
/* FIND WORD */
if (Post_ss) {
for(p1 = *next;
((*p1 NE NULL) AND
((even_delim EQ NO) OR
(*p1 NE SPACE AND *p1 NE TAB AND *p1 NE DASH)))
;p1++) {
if(*p1 EQ Post_ss_delim) {
if (even_delim) even_delim = NO;
else even_delim = YES;
}
}
}
else {
for(p1 = *next;
((*p1 NE NULL) AND
(*p1 NE SPACE AND *p1 NE TAB AND *p1 NE DASH))
;p1++)
;
}
if ((*p1 EQ NULL) AND (even_delim EQ NO)) {
fprintf(STDERR,
"Fatal error in line %d:\n%s%s",
In_linecnt,
"opening post-formatting string substitution delimiter\n",
"without closing delimiter.\n");
exit(0);
}
/* ALLOW BREAK AT DASH BUT INCLUDE DASH IN WORD */
if (*p1 EQ DASH) p1++;
/* SET EXTERNALS */
Wordbegin = *next;
Wordend = p1 - 1;
Wordlen = p1 - *next;
*next = p1;
/* Wordlen CORRECTION ROUTINE */
for (p1 = Wordbegin; p1 <= Wordend; p1++) {
if (Post_ss AND *p1 EQ Post_ss_delim) {
/* IF NO CHARACTERS BETWEEN COMMAND DELIMITERS, LEAVE FOR
LATER SUBSTITUTION OF A SINGLE COMMAND DELIMITER TO BE
PRINTED. */
if (*p1+1 EQ Post_ss_delim) {
Wordlen -= 1;
p1++; /* IGNORE SECOND COMMAND DELIMITER IN THE PRESENT
FOR LOOP */
continue;
}
else {
/* FIND CLOSING DELIMITER */
for (p2 = p1+1; *p2 NE Post_ss_delim; p2++)
;
/* CORRECT Wordlen */
Wordlen -= (p2 - p1 + 1);
/* CONTINUE SCANNING AFTER THE TERMINAL DELIMITER */
p1 = p2; /* for loop will now p1++ */
}
}
else if (*p1 EQ BACKSPACE) Wordlen -= 2;
}
#ifdef DEBUG
if (Debug) {
fprintf(STDERR,"Getwrd: \"");
for (p1 = Wordbegin; p1 <= Wordend; p1++) putc(*p1,STDERR);
fprintf(STDERR,"\" (Wordlen = %d)\n",Wordlen);
}
#endif
return(1);
}
/*-------------------------------------------------------------------------*/
getspaces(next)
/* DETERMINES THE VALUE OF Spacecnt, WHICH IS THE NUMBER OF SPACES WHICH
SHOULD SEPARATE THE PREVIOUS WORD FROM THE NEXT WORD. NOTE THAT EXPANSION OF
NON-LEADING TABS IS NOT APPLICABLE WHEN FILLING, i. e. IN THIS FUNCTION */
char **next;
{
Spacecnt = 0;
while (**next EQ SPACE OR
**next EQ TAB OR
**next EQ NULL) {
Spacecnt++; /* formerly Spacecnt=1 */
if (**next NE NULL) (*next)++;
else break;
}
/*
/* PUT 2 SPACES AFTER PERIOD ENDING SENTENCE IF
1. NEXT WORD IS CAPITALIZED
2. PRECEDING WORD IS LONGER THAN 2 LETTERS (FOR INITIALS, Wm., Dr.)
*/
if (*Wordend EQ '.' AND (Wordlen > 3)
AND Spacecnt AND (isupper(**next)))
Spacecnt = 2;
*/
/* IF THE PREVIOUS WORD ENDS IN A DASH AT THE END OF THE LINE, THEN WE
ARE IN THE MIDDLE OF A HYPHENATED WORD AND NO SPACES SHOULD FOLLOW THE
DASH. */
if (*Wordend EQ DASH
AND ((*next - Wordend) EQ 1)
AND (**next EQ NULL)) Spacecnt = 0;
#ifdef DEBUG
if (Debug) fprintf(STDERR,"Getspaces: Spacecnt = %d\n",Spacecnt);
#endif
}
/*-------------------------------------------------------------------------*/
putwrd() {
int newlen, line_len, indelim;
char *p1;
#ifdef DEBUG
if (Debug) fprintf(STDERR,"putwrd(entry)");
#endif
line_len = Rmval - Tival;
newlen = Outlen + Wordlen + Spacecnt;
if (newlen > line_len) {
if (!Sanders AND Justify) {
spread (Outbuf, line_len - Outlen + 1, Outwrds);
}
if (Sanders AND Justify) brk(FORCEPRINT);
else brk(CR);
}
if (Wordlen) Outwrds++;
for (p1 = Wordbegin; p1 <= Wordend; p1++) {
#ifdef DEBUG
if (Debug) putc(*p1,STDERR);
#endif
*(Nextout++) = *p1;
}
if (Spacecnt < 0 OR Wordlen < 0) {
fprintf(STDERR,
"Wordlen=%d, Spacecnt=%d, EXIT IN getwrd()\n",
Wordlen,Spacecnt);
exit(0);
}
fillbuf(&Nextout, SPACE, Spacecnt);
Outlen += Wordlen + Spacecnt;
#ifdef DEBUG
if (Debug) fprintf(STDERR,
"(return)Outwrds=%d Outlen=%d\n",Outwrds,Outlen);
#endif
}
/*-------------------------------------------------------------------------*/
fillbuf(next, c, cnt)
char c, **next;
int cnt;
{
while (cnt--) {
**next = c;
*next += 1;
}
}
/*-------------------------------------------------------------------------*/
fillulbuf(textline)
char *textline;
{
int indelim;
char *p, *nextul, *pflip;
#ifdef DEBUG
if (Debug) fprintf(STDERR,"Fillulbuf\n");
#endif
pflip = getflip('U', Ul_plus, textline);
if (!pflip) {
*Ulbuf = NULL;
return(0);
}
nextul = Ulbuf;
indelim = NO;
for(p = textline; *p; p++) {
/* SET Ul_plus */
if (p EQ pflip) {
Ul_plus? Ul_plus=NO: Ul_plus=YES;
pflip = getflip('U', Ul_plus, pflip+1);
}
/* SKIP POST SUBSTITUTIONS */
if (Post_ss AND *p EQ Post_ss_delim) {
if (indelim) {
indelim = NO;
continue;
}
else indelim = YES;
}
if (indelim) continue;
if (*p EQ BACKSPACE) {
nextul--;
continue;
}
if (Ul_plus AND (isalpha(*p) OR isdigit(*p)))
*nextul++ = '_';
else *nextul++ = SPACE;
}
*nextul = NULL;
}
/*-------------------------------------------------------------------------*/
boldonly(textline)
char *textline;
{
int indelim;
char *p, *nextul, *pflip;
#ifdef DEBUG
if (Debug) fprintf(STDERR,"BOLDONLY\n");
#endif
pflip = getflip('B', Bo_plus, textline);
if (!pflip) return(NO);
indelim = NO;
for(p = textline; *p; p++) {
/* SET Bo_plus */
if (p EQ pflip) {
Bo_plus? Bo_plus=NO: Bo_plus=YES;
pflip = getflip('B', Bo_plus, pflip+1);
}
/* SKIP POST SUBSTITUTIONS */
if (Post_ss AND *p EQ Post_ss_delim) {
if (indelim) {
indelim = NO;
continue;
}
else indelim = YES;
}
if (indelim OR
(*p EQ BACKSPACE) OR
Bo_plus
) continue;
else *p = SPACE;
}
return(YES);
}
/*-------------------------------------------------------------------------*/
getflip(type, status, previous)
char type, *previous;
int status;
{
char flip[16];
char